﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Core/Core</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Core">Core</a></h4>
      <div class="menu-item"><a href="#Core:typeOf">typeOf</a></div>
			<div class="menu-item"><a href="#Core:instanceOf">instanceOf</a></div>
			<div class="menu-item"><a href="#Type:implement">implement</a></div>
			<div class="menu-item"><a href="#Type:extend">extend</a></div>
			<div class="menu-item"><a href="#Type:generics">generics</a></div>
      <h4 class="menu-item"><a href="#Deprecated-Functions">Deprecated.Functions</a></h4>
      <div class="menu-item"><a href="#Deprecated-Functions:chk">chk</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:clear">clear</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:defined">defined</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:arguments">arguments</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:empty">empty</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:lambda">lambda</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:extend">extend</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:merge">merge</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:each">each</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:pick">pick</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:random">random</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:splat">splat</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:time">time</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:try">try</a></div>
      <div class="menu-item"><a href="#Deprecated-Functions:type">type</a></div>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="Core"><a href="#Core">Type: Core</a></h1>

<p class="description">Core contains common functions used in <a href="http://mootools.net/">MooTools</a>.</p>

<h2 id="Core:typeOf"><a href="#Core:typeOf">Function: typeOf</a></h2>

<p class="description">Returns the type of an object.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw1">typeOf</span><span class="br0">(</span>obj<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>obj - (<em>object</em>) The object to inspect.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>'element'    - (<em>string</em>) If object is a DOM element node.</li>
<li>'elements'   - (<em>string</em>) If object is an instance of <a href="../element/element.html">Elements</a>.</li>
<li>'textnode'   - (<em>string</em>) If object is a DOM text node.</li>
<li>'whitespace' - (<em>string</em>) If object is a DOM whitespace node.</li>
<li>'arguments'  - (<em>string</em>) If object is an arguments object.</li>
<li>'array'      - (<em>string</em>) If object is an array.</li>
<li>'object'     - (<em>string</em>) If object is an object.</li>
<li>'string'     - (<em>string</em>) If object is a string.</li>
<li>'number'     - (<em>string</em>) If object is a number.</li>
<li>'date'       - (<em>string</em>) If object is a date.</li>
<li>'boolean'    - (<em>string</em>) If object is a boolean.</li>
<li>'function'   - (<em>string</em>) If object is a function.</li>
<li>'regexp'     - (<em>string</em>) If object is a regular expression.</li>
<li>'class'      - (<em>string</em>) If object is a <a href="../class/class.html">Class</a> (created with new Class or the extend of another class).</li>
<li>'collection' - (<em>string</em>) If object is a native HTML elements collection, such as childNodes or getElementsByTagName.</li>
<li>'window'     - (<em>string</em>) If object is the window object.</li>
<li>'document'   - (<em>string</em>) If object is the document object.</li>
<li>'domevent'   - (<em>string</em>) If object is an event.</li>
<li>'null'       - (<em>string</em>) If object is undefined, null, NaN or none of the above.</li>
</ul>
<h3>Example:</h3>

<pre class="javascript"><span class="kw2">var</span> myString = <span class="st0">'hello'</span>;
<span class="kw1">typeOf</span><span class="br0">(</span>myString<span class="br0">)</span>; <span class="co1">// returns "string"</span>
</pre>

<h3>Note:</h3>

<p>This method is equivalent to <em>$type</em> from MooTools 1.2, with the exception that undefined and null values now return 'null' as a string, instead of false.</p>

<h2 id="Core:instanceOf"><a href="#Core:instanceOf">Function: instanceOf</a></h2>

<p class="description">Checks if an object is an instance of a particular type.</p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw1">instanceOf</span><span class="br0">(</span><span class="kw1">item</span>, object<span class="br0">)</span>
</pre>

<h3>Arguments:</h3>

<ol>
<li>item - (<em>mixed</em>) The item to check.</li>
<li>object - (<em>mixed</em>) The type to compare it with.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>boolean</em>) Whether or not the item is an instance of the object.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript"><span class="kw2">var</span> foo = <span class="br0">[</span><span class="br0">]</span>;
<span class="kw1">instanceOf</span><span class="br0">(</span>foo, Array<span class="br0">)</span> <span class="co1">// returns true</span>
<span class="kw1">instanceOf</span><span class="br0">(</span>foo, String<span class="br0">)</span> <span class="co1">// returns false</span>
&nbsp;
<span class="kw2">var</span> myClass = <span class="kw2">new</span> <span class="kw2">Class</span><span class="br0">(</span><span class="br0">)</span>;
<span class="kw2">var</span> bar = <span class="kw2">new</span> myClass<span class="br0">(</span><span class="br0">)</span>;
<span class="kw1">instanceOf</span><span class="br0">(</span>bar, myClass<span class="br0">)</span> <span class="co1">// returns true</span>
</pre>

<h3 id="Type">Type</h3>

<p>MooTools extends native types, like string, array or number to make them even more useful.</p>

<p>The types MooTools uses are:</p>

<ul>
<li>String</li>
<li>Array</li>
<li>Number</li>
<li>Function</li>
<li>RegExp</li>
<li>Date</li>
<li>Boolean</li>
</ul>
<p>Custom MooTools types are:</p>

<ul>
<li>Element</li>
<li>Elements</li>
<li>Event</li>
</ul>
<h2 id="Type:implement"><a href="#Type:implement">Type method: implement</a></h2>

<p class="description">This method implements a new method to the type's prototype.</p>

<h3>Syntax:</h3>

<pre class="javascript">myType.<span class="me1">implement</span><span class="br0">(</span><span class="kw3">name</span>, method<span class="br0">)</span>;
</pre>

<p><strong>or</strong></p>

<pre class="javascript">myType.<span class="me1">implement</span><span class="br0">(</span>methods<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>name - (<em>string</em>) The method name.</li>
<li>method - (<em>function</em>) The method function.</li>
</ol>
<p><strong>or</strong></p>

<ol>
<li>methods - (<em>object</em>) An object with key-value pairs. The key is the method name, the value is the method function.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>object</em>) The type.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript">Array.<span class="me1">implement</span><span class="br0">(</span><span class="st0">'limitTop'</span>, <span class="kw2">function</span><span class="br0">(</span>top<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">for</span> <span class="br0">(</span><span class="kw2">var</span> i = <span class="nu0">0</span>, l = <span class="kw1">this</span>.<span class="me1">length</span>; i &lt; l; i++<span class="br0">)</span><span class="br0">{</span>
        <span class="kw1">if</span> <span class="br0">(</span><span class="kw1">this</span><span class="br0">[</span>i<span class="br0">]</span> &gt; top<span class="br0">)</span> <span class="kw1">this</span><span class="br0">[</span>i<span class="br0">]</span> = top;
    <span class="br0">}</span>
    <span class="kw1">return</span> <span class="kw1">this</span>;
<span class="br0">}</span><span class="br0">)</span>;
&nbsp;
<span class="br0">[</span><span class="nu0">1</span>, <span class="nu0">2</span>, <span class="nu0">3</span>, <span class="nu0">4</span>, <span class="nu0">5</span>, <span class="nu0">6</span><span class="br0">]</span>.<span class="me1">limitTop</span><span class="br0">(</span><span class="nu0">4</span><span class="br0">)</span>; <span class="co1">// returns [1, 2, 3, 4, 4, 4]</span>
</pre>

<p>It is also possible to pass an object of methods:</p>

<pre class="javascript">String.<span class="me1">implement</span><span class="br0">(</span><span class="br0">{</span>
    repeat: <span class="kw2">function</span><span class="br0">(</span>times<span class="br0">)</span><span class="br0">{</span>
        <span class="kw2">var</span> string = <span class="st0">''</span>;
        <span class="kw1">while</span> <span class="br0">(</span>times--<span class="br0">)</span> string += <span class="kw1">this</span>;
        <span class="kw1">return</span> string;
    <span class="br0">}</span>,
    ftw: <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
        <span class="kw1">return</span> <span class="kw1">this</span> + <span class="st0">' FTW!'</span>;
    <span class="br0">}</span>
<span class="br0">}</span><span class="br0">)</span>;
&nbsp;
<span class="st0">'moo! '</span>.<span class="me1">repeat</span><span class="br0">(</span><span class="nu0">3</span><span class="br0">)</span>; <span class="co1">// returns "moo! moo! moo! "</span>
<span class="st0">'MooTools'</span>.<span class="me1">ftw</span><span class="br0">(</span><span class="br0">)</span>; <span class="co1">// returns "MooTools FTW!"</span>
<span class="br0">(</span><span class="st0">'MooTools'</span>.<span class="me1">ftw</span><span class="br0">(</span><span class="br0">)</span> + <span class="st0">' '</span><span class="br0">)</span>.<span class="me1">repeat</span><span class="br0">(</span><span class="nu0">2</span><span class="br0">)</span>; <span class="co1">// returns "MooTools FTW! MooTools FTW! "</span>
</pre>

<h2 id="Type:extend"><a href="#Type:extend">Type method: extend</a></h2>

<p class="description">Adds one or more functions to the type. These are static functions that accept for example other types to parse them into the type, or other utility functions that belong to the certain type.</p>

<h3>Syntax:</h3>

<pre class="javascript">myType.<span class="me1">extend</span><span class="br0">(</span><span class="kw3">name</span>, method<span class="br0">)</span>;
</pre>

<p><strong>or</strong></p>

<pre class="javascript">myType.<span class="me1">extend</span><span class="br0">(</span>methods<span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>name - (<em>string</em>) The method name.</li>
<li>method - (<em>function</em>) The method function.</li>
</ol>
<p><strong>or</strong></p>

<ol>
<li>methods - (<em>object</em>) An object with key-value pairs. The key is the method name, the value is the method function.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>object</em>) The type.</li>
</ul>
<h3>Examples:</h3>

<pre class="javascript">RegExp.<span class="me1">extend</span><span class="br0">(</span><span class="st0">'from'</span>, <span class="kw2">function</span><span class="br0">(</span>regexp, flags<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="kw2">new</span> RegExp<span class="br0">(</span>regexp, flags<span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>;
&nbsp;
Number.<span class="me1">extend</span><span class="br0">(</span><span class="st0">'parseCurrency'</span>, <span class="kw2">function</span><span class="br0">(</span>currency<span class="br0">)</span><span class="br0">{</span>
    <span class="co1">// takes a string and transforms it into a number to</span>
    <span class="co1">// do certain calculations</span>
<span class="br0">}</span><span class="br0">)</span>;
</pre>

<h2 id="Type:generics"><a href="#Type:generics">Generics</a></h2>

<p class="description">Most methods of types can be used as generic functions. These are the already existing JavaScript methods, methods MooTools adds, or methods you <a href="#Type:implement">implemented</a> yourself.</p>

<h3>Example:</h3>

<pre class="javascript"><span class="kw2">var</span> everyArgBiggerThanTwo = <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
    <span class="co1">// Instead of this</span>
    <span class="kw1">return</span> Array.<span class="me1">prototype</span>.<span class="me1">every</span>.<span class="me1">call</span><span class="br0">(</span>arguments, someFunction<span class="br0">)</span>;
    <span class="co1">// you can use</span>
    <span class="kw1">return</span> Array.<span class="me1">every</span><span class="br0">(</span>arguments, someFunction<span class="br0">)</span>;
<span class="br0">}</span>;
</pre>

<p>This is useful if methods of a certain type should be used as function of another type.
 As the example above, it is used for the Arguments type, which is not a real array, so <code>arguments.every(fn)</code> would not work. However, <code>Array.every(arguments, fn)</code> does work in MooTools.</p>

<h3>Syntax:</h3>

<pre class="javascript">Type.<span class="me1">methodName</span><span class="br0">(</span>thisArg<span class="br0">[</span>, arg1, arg2, ...<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>thisArg - (<em>mixed</em>) This is the subject, which is usually <code>thisArg.method([arg1, arg2, ...]);</code>.</li>
<li>arg1, arg2, ... - (<em>mixed</em>) Additional arguments which will be passed as method arguments.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>mixed</em>) Anything the method usually returns.</li>
</ul>
<hr>

      <h1 id="Deprecated-Functions"><a href="#Deprecated-Functions">Deprecated Functions</a></h1>
      <h2 id="Deprecated-Functions:chk" class="description"><a href="#Deprecated-Functions:chk">Function: $chk</a></h2>
      <p class="description">This method has been deprecated and will have no equivalent in MooTools 2.0.</p>
      <p>If you really need this function you can implement it like so:</p>
      <h3>Example:</h3>
      <pre class="javascript"><span class="kw2">var</span> $chk = <span class="kw2">function</span><span class="br0">(</span>obj<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> !!<span class="br0">(</span>obj || obj === <span class="nu0">0</span><span class="br0">)</span>;

<span class="br0">}</span>;
</pre>
      <h2 id="Deprecated-Functions:clear"><a href="#Deprecated-Functions:clear">Function: $clear</a></h2>
      <p class="description">This method has been deprecated. Please use <em>clearInterval</em> or <em>clearTimeout</em> instead.</p>
      <h3>See Also:</h3>
      <ul>
        <li> <a href="https://developer.mozilla.org/en/DOM/window.clearTimeout">MDC clearTimeout</a>, <a href="https://developer.mozilla.org/en/DOM/window.clearInterval">MDC clearInterval</a> </li>
      </ul>
      <h2 id="Deprecated-Functions:defined"><a href="#Deprecated-Functions:defined">Function: $defined</a></h2>
      <p class="description">This method has been deprecated.</p>
      <p>If you really need this function you can implement it like so:</p>
      <h3>Example:</h3>
      <pre class="javascript"><span class="kw2">var</span> $defined = <span class="kw2">function</span><span class="br0">(</span>obj<span class="br0">)</span><span class="br0">{</span>
    <span class="kw1">return</span> <span class="br0">(</span>obj != undefined<span class="br0">)</span>;

<span class="br0">}</span>;
&nbsp;
<span class="co1">// or just use it like this:</span>
<span class="kw1">if</span><span class="br0">(</span>obj != undefined<span class="br0">)</span><span class="br0">{</span>
    <span class="co1">// do something</span>
<span class="br0">}</span>
</pre>
      <h2 id="Deprecated-Functions:arguments"><a href="#Deprecated-Functions:arguments">Function: $arguments</a></h2>
      <p class="description">This method has been deprecated and will have no equivalent in MooTools 2.0.</p>
      <p>If you really need this function you can implement it like so:</p>
      <h3>Example:</h3>
      <pre class="javascript"><span class="kw2">var</span> $arguments = <span class="kw2">function</span><span class="br0">(</span>i<span class="br0">)</span><span class="br0">{</span>

    <span class="kw1">return</span> <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span>
        <span class="kw1">return</span> arguments<span class="br0">[</span>i<span class="br0">]</span>;
    <span class="br0">}</span>;

<span class="br0">}</span>;
</pre>
      <h2 id="Deprecated-Functions:empty"><a href="#Deprecated-Functions:empty">Function: $empty</a></h2>
      <p class="description">This method has been deprecated. Use <a href="../../../docs/core/Types/Function.html#Function:Function-from">Function.from</a> instead.</p>
      <h3>Example:</h3>
      <pre class="javascript"><span class="kw2">var</span> myFunc = <span class="kw2">Function</span>.<span class="me1">from</span><span class="br0">(</span><span class="br0">)</span>;

<span class="co1">// or better:</span>
<span class="kw2">var</span> myFunc = <span class="kw2">function</span><span class="br0">(</span><span class="br0">)</span><span class="br0">{</span><span class="br0">}</span>;
</pre>
      <h2 id="Deprecated-Functions:lambda"><a href="#Deprecated-Functions:lambda">Function: $lambda</a></h2>
      <p class="description">This method has been deprecated. Use <a href="../../../docs/core/Types/Function.html#Function:Function-from">Function.from</a> instead.</p>
      <h3>Example:</h3>
      <pre class="javascript">myLink.<span class="me1">addEvent</span><span class="br0">(</span><span class="st0">'click'</span>, <span class="kw2">Function</span>.<span class="me1">from</span><span class="br0">(</span><span class="kw2">false</span><span class="br0">)</span><span class="br0">)</span>; <span class="co1">// prevents a link Element from being clickable</span>

</pre>
      <h2 id="Deprecated-Functions:extend"><a href="#Deprecated-Functions:extend">Function: $extend</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="../../../docs/core/Types/Object.html#Object:Object-append">Object.append</a> instead.</p>
      <h2 id="Deprecated-Functions:merge"><a href="#Deprecated-Functions:merge">Function: $merge</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="../../../docs/core/Types/Object.html#Object:Object-merge">Object.merge</a> instead.</p>
      <h2 id="Deprecated-Functions:each"><a href="#Deprecated-Functions:each">Function: $each</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="../../../docs/core/Types/Array.html#Array:Array-each">Array.each</a> or <a href="../../../docs/core/Types/Object.html#Object:Object-each">Object.each</a> instead.</p>
      <h2 id="Deprecated-Functions:pick"><a href="#Deprecated-Functions:pick">Function: $pick</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="../../../docs/core/Types/Array.html#Array:pick">Array.pick</a> instead.</p>
      <h2 id="Deprecated-Functions:random"><a href="#Deprecated-Functions:random">Function: $random</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="../../../docs/core/Types/Number.html#Number:Number-random">Number.random</a> instead.</p>
      <h2 id="Deprecated-Functions:splat"><a href="#Deprecated-Functions:splat">Function: $splat</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="../../../docs/core/Types/Array.html#Array:Array-from">Array.from</a> instead.</p>
      <h2 id="Deprecated-Functions:time"><a href="#Deprecated-Functions:time">Function: $time</a></h2>
      <p class="description">This method has been deprecated. Please use <em>Date.now()</em> instead.</p>
      <h3>Syntax:</h3>
      <pre class="javascript"><span class="kw2">var</span> time = Date.<span class="me1">now</span><span class="br0">(</span><span class="br0">)</span>;

</pre>
      <h3>Returns:</h3>
      <ul>
        <li>(<em>number</em>) - The current timestamp.</li>
      </ul>
      <h2 id="Deprecated-Functions:try"><a href="#Deprecated-Functions:try">Function: $try</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="../../../docs/core/Types/Function.html#Function:Function-attempt">Function.attempt</a> instead.</p>
      <h2 id="Deprecated-Functions:type"><a href="#Deprecated-Functions:type">Function: $type</a></h2>
      <p class="description">This method has been deprecated. Please use <a href="#Core:typeOf">typeOf</a> instead.</p>
    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
